/**
 * 
 */
package fr.utbm.gi.in56.database;

import java.io.Serializable;
import java.sql.*;
import java.util.Date;

/**
 * Implementation of a connection object container.
 *
 * @author Adrien Hoffer & Tarik Belabbas
 *
 */
public class ConnectionObject implements Serializable
{
	/**
	 * Version number associated to the serializable class.
	 */
	private static final long	serialVersionUID	= -2708758053466057921L;


	/**
	 * The connection.
	 */
	private Connection	connection;
	
	
	/**
	 * The number time connection was used.
	 */
	private int			useCount;
	
	/**
	 * The  last time the connection was accessed.
	 */
	private Date		lastAccessTime;
	
	/**
	 * Boolean to set if the connection is in use. 
	 */
	private boolean		inUse;

	/**
	 * Returns the connection.
	 * 
	 * @return the connection
	 */
	public Connection getConnection()
	{
		return connection;
	}

	/**
	 * Returns the use counter.
	 * 
	 * @return the use counter
	 */
	public int getUseCount()
	{
		return useCount;
	}

	/**
	 * Returns the last time the connection was accessed.
	 * 
	 * @return the last time the connection was accessed
	 */
	public Date getLastAccessTime()
	{
		return lastAccessTime;
	}

	/**
	 * Returns if the connection is in use.
	 * 
	 * @return <tt>true</tt> if the connection is in use
	 */
	public boolean getInUse()
	{
		return inUse;
	}

	/**
	 * Sets the connection
	 * 
	 * @param _connection the new connection
	 */
	public void setConnection( Connection _connection )
	{
		connection = _connection;
	}

	/**
	 * Sets the use counter.
	 * 
	 * @param _useCount the new count
	 */
	public void setUseCount( int _useCount )
	{
		useCount = _useCount;
	}

	/**
	 * Sets the last time the connection was accessed.
	 * 
	 * @param _lastAccessTime the new time
	 */
	public void setLastAccessTime( Date _lastAccessTime )
	{
		lastAccessTime = _lastAccessTime;
	}

	/**
	 * Sets if the connection is in used.
	 * 
	 * @param _inUse <tt>true</tt> if the connection is in use
	 */
	public void setInUse( boolean _inUse )
	{
		inUse = _inUse;
	}

	/**
	 * Returns if the connection is available, i.e. not used.
	 * 
	 * @return <tt>true</tt> if the connection is available
	 */
	public boolean isAvailable()
	{
		return !inUse;
	}
}
